<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('修改配置信息')}" />
    <style>
        .form-group span{
            color: red;
        }
    </style>
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <form class="form-horizontal m" id="form-profile-edit" th:object="${websiteProfile}">
        <input id="modelType"  th:value="${modelType}" type="hidden"/>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">appId</label>
            <div class="col-sm-6">
                <input id="appId" name="appId" class="form-control" th:value="*{get('appId')}" type="text">
                <span>（微信网站登录，网站应用appId）</span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">appSecret</label>
            <div class="col-sm-6">
                <input id="appSecret" name="appSecret" class="form-control" th:value="*{get('appSecret')}" type="text">
                <span>（微信网站登录，网站应用appSecret）</span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">强制授权</label>
            <div class="col-sm-6">
                <select name="forceLogin" id="forceLogin"  class="form-control m-b" th:with="type=${@dict.getType('qdx_switch_type')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
                <span>（微信内置浏览，是否强制授权登录）</span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">snsAppId</label>
            <div class="col-sm-6">
                <input id="snsAppId" name="snsAppId" class="form-control" th:value="*{get('snsAppId')}" type="text">
                <span>（微信内置登录，公众号appId）</span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label text-sm-right">snsAppSecret</label>
            <div class="col-sm-6">
                <input id="snsAppSecret" name="snsAppSecret" class="form-control" th:value="*{get('snsAppSecret')}" type="text">
                <span>（微信内置登录，公众号appSecret）</span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2"></label>
            <div class="col-sm-offset-2 col-sm-6">
                <button type="button" class="btn btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-danger" onclick="window.parent.layer.closeAll()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<script type="text/javascript">

    var prefix = "/profile";

    $(function () {
        $("#forceLogin").val("[[${websiteProfile.get('forceLogin')}]]");
    })

    function submitHandler() {
        var modelType = $("#modelType").val();
        if ($.validate.form()) {
            var baseInfo = {};
            var formArray = $("#form-profile-edit").serializeArray();
            $.each(formArray, function (i, item) {
                baseInfo[item.name] = item.value;
            });
            var description = JSON.stringify(baseInfo);
            $.post(prefix + "/save.json", {"type": modelType, "description": description}, function (json) {
                console.log(json)
                if (json.code === 0) {
                    window.parent.layer.closeAll();
                }
            })
        }
    }
</script>
</body>
</html>